package com.cs.framework.core.context.xml;

import org.springframework.beans.factory.xml.DefaultDocumentLoader;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;

import com.cs.framework.web.exception.WebExceptionHelper;

/**
 * 供模块使用的XML解析器
 * 
 * @author hedongzhou
 * 
 */
public class ModuleDocumentLoader extends DefaultDocumentLoader {

	/**
	 * 重写loadDocument方法
	 */
	public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler,
			int validationMode, boolean namespaceAware) throws Exception {
		// 解析xml
		Document doc = super.loadDocument(inputSource, entityResolver, errorHandler, validationMode, namespaceAware);

		// 判断是否存在自动扫描标签元素
		NodeList list = doc.getElementsByTagName("context:component-scan");
		if (list.getLength() > 0) {
			WebExceptionHelper.throwWebException("W010", "context:component-scan");
		}

		return doc;
	}

}
